package org.wu.framework.lazy.orm.database.jpa.repository.support.update;

import org.wu.framework.lazy.orm.database.jpa.repository.query.LazyQueryMetadata;
import org.wu.framework.lazy.orm.database.jpa.repository.support.AbstractLazySimpleQuerySupport;
import org.wu.framework.lazy.orm.database.lambda.domain.PersistenceRepository;
import org.wu.framework.lazy.orm.database.lambda.stream.lambda.LazyLambdaStream;

public class LazySimpleUpdateQuerySupport extends AbstractLazySimpleQuerySupport {

    private final LazyQueryMetadata lazyQueryMetadata;

    public LazySimpleUpdateQuerySupport(LazyQueryMetadata lazyQueryMetadata) {
        super(lazyQueryMetadata);
        this.lazyQueryMetadata = lazyQueryMetadata;
    }

    /**
     * 执行
     *
     * @return T
     */
    @Override
    protected <T> T doQuery() {
        PersistenceRepository persistenceRepository = lazyQueryMetadata2PersistenceRepository(lazyQueryMetadata);
        persistenceRepository.setResultClass(Long.class);
        LazyLambdaStream lazyLambdaStream = lazyQueryMetadata.getLazyLambdaStream();
        return (T) lazyLambdaStream.executeOne(persistenceRepository);
    }
}
